package com.example.accessdemo.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.util.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.accessdemo.domain.SysDept;
import com.example.accessdemo.service.SysDeptService;
import com.example.accessdemo.mapper.SysDeptMapper;
import org.springframework.stereotype.Service;

/**
* @author kuangdda
* @description 针对表【sys_dept(部门表)】的数据库操作Service实现
* @createDate 2023-06-07 16:08:11
*/
@Service
public class SysDeptServiceImpl extends ServiceImpl<SysDeptMapper, SysDept>
    implements SysDeptService{
    
    /**
     * 通过ID获取当前资产的名称，递归获取上级资产ID及上级资产名称并行拼接
     * @param id 资产ID
     * @return 当前资产在整个系统中的中文全称
     */
    public String buildFullName(String id){
        SysDept byId = this.getById(Integer.parseInt(id));
        StringBuilder fullName = new StringBuilder();
        
        if (ObjectUtil.isNull(byId)){
            return fullName.toString();
        }
        /**
         * 最顶层不加入拼接
         */
        if (StringUtils.isNotBlank(String.valueOf(byId.getParent_id())) && byId.getParent_id() != 0l){
            fullName.insert(0,byId.getDept_name());
        }
        return fullName.insert(0,buildFullName(String.valueOf(byId.getParent_id()))).toString();
    }

}




